package com.ydgk.dao;

import com.ydgk.bean.Bill;
import org.springframework.jdbc.core.BeanPropertyRowMapper;

import java.util.List;

public class BillDao extends BaseDao<Bill>{
    @Override
    public int save(Bill bill) {
        return this.template.update("insert into bill values(null,?,?,?,?,?,?)",bill.getBname(),bill.getBcomm(),bill.getBcnum(),bill.getBprice(),bill.getBprovider(),bill.getBdate());
    }

    @Override
    public int updateById(Bill bill) {
        return 0;
    }

    @Override
    public int deleteById(int id) {
        return 0;
    }

    @Override
    public List<Bill> findAll() {
        return this.template.query("select * from bill",new BeanPropertyRowMapper<Bill>(Bill.class));
    }

    @Override
    public Bill findById(int id) {
        return null;
    }

    @Override
    public List<Bill> paging(int pageNumber) {
        return this.template.query("select * from bill order by bid desc limit ?,?",
                new BeanPropertyRowMapper<>(Bill.class),(pageNumber-1)*pageCount,pageCount);
    }

    public int total(){
        return this.template.queryForObject("select count(*) from bill",Integer.class);
    }

}
